package com.yumi.shizhan;

import jakarta.annotation.Resource;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.stereotype.Service;

import java.util.Random;

@Service("inkService")
public class InkServiceImpl implements InkService{

    @Autowired
    @Qualifier("moSize")
    private InkDao inkDao;

    public InkDao Ink() {
        return inkDao;
    }

    public void Ink(InkDao inkDao) {
        this.inkDao = inkDao;
    }

    @Override
    public void serve(Entity entity) {
        int randomNum = new Random().nextInt(10); // 0-9
        System.out.println("随机数: " + randomNum); // 调试用

        if (randomNum < 5) {
            // 正常情况
            System.out.println("正常执行: " + entity.getColor() + ", " + entity.getSize());
        }
        else if (randomNum >= 5 && randomNum < 7) {
            // 5-6: 卡纸异常
            throw new PaperJamException("卡纸了！随机数=" + randomNum);
        }
        else {
            // 7-9: 墨盒无墨异常
            throw new InkEmptyException("墨盒没墨了！随机数=" + randomNum);
        }
    }

    public void setInkDao(CaiSize inkDao) {
        this.inkDao = inkDao;
    }

    public void setInkDao(MoSize inkDao) {
        this.inkDao = inkDao;
    }
}
